package com.sxt.springcloud.sys.fallback;

import com.sxt.springcloud.sys.DeptClientService;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import com.sxt.sys.vo.DeptVo;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
@Component
public class DeptClientFallbackService implements FallbackFactory {
    @Override
    public Object create(Throwable throwable) {
        return new DeptClientService() {
            @Override
            public DataGridView loadDeptManagerLeftTreeJson(DeptVo deptVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询部门管理左侧树方法失败");
            }

            @Override
            public DataGridView loadAllDept(DeptVo deptVo) {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用查询所有部门方法失败");
            }

            @Override
            public Map<String, Object> loadDeptMaxOrderNum() {
                Map<String, Object> map = new HashMap<>();
                map.put("服务器忙","服务降级，服务器忙，请稍后重试！调用查询部门最大值失败");
                return map;
            }

            @Override
            public ResultObj addDept(DeptVo deptVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public ResultObj updateDept(DeptVo deptVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public Map<String, Object> checkDeptHasChildrenNode(DeptVo deptVo) {
                Map<String, Object> map = new HashMap<>();
                 map.put("服务器忙","服务降级，服务器忙，请稍后重试！调用检测是否有子部门方法失败");
                return map;
            }

            @Override
            public ResultObj deleteDept(DeptVo deptVo) {
                return ResultObj.SERVER_BUSY;
            }

            @Override
            public DataGridView loadDetpForSelectById() {
                return new DataGridView("服务降级，服务器忙，请稍后重试！调用根据选择id查询部门方法失败");
            }
        };
    }
}
